
<cfcomponent displayname="FormQuery">
	<cffunction name="GetTheForm" access="public" returntype="query">
		<cfargument name="rightID" type="string" required="yes">
		<cfargument name="typeID" type="string" required="yes">
		<cfargument name="tDSN" type="string" required="yes">
		
		<cfquery name="getForm" datasource="#tDSN#">
			SELECT 
		<!--- E.*, --->
				E.FORMCODE, E.FORMGROUP, E.FORMTYPE, E.DESCRIPTION, E.PREPROCESSPROMPT, E.PREPROMPTMPLATE, E.PREUP2RCPTLEVEL,E.ENABLEBATCHAPPLY,
				E.TABLENAME_FK, E.PK_FIELD1, E.PK_FIELD2, E.PK_FIELD3,
				E.PK_FIELD4, E.PK_FIELD5, E.TEMPLATECODE_FK, E.ICONNAME,
				E.PROCESSCODE, E.RECORDFILTER, E.CALENDARFIELD,
				E.MASTERDETAIL, E.PREPROCESS, E.PREPROCESSTITLE,
				E.DEFAULTORDER, E.DEFAULTASCDESC, E.PREPROMPTTITLE,
				E.COPYTOFORMCODE, E.FLDFORLATEAPPS, E.GRACEPRDLATEAPPS,
				E.LATEAPPSMODE, E.ENABLEATTACHMENTS,E.ENABLEMAILAPPROV,E.ATTACHEDMAIL,E.ATTACHEDLINK,
				E1.ISADD, E1.ISEDIT, E1.ISDELETE, E1.ISVIEW, E1.ISEMAIL,E1.ISPRINT,E.ENABLEGROUPROUTE,E.MULTIPLEFORMFLOW,E1.BATCHAPPLY
			FROM ECRGFORMS E, ECRTFORMS E1
			WHERE
				(E1.USERGRPID_FK IN (#preserveSingleQuotes(rightID)#)) AND
				(E1.FORMCODE_FK  = E.FORMCODE) AND
				(E1.FORMCODE_FK  = '#typeID#')
		</cfquery>
		
		<cfreturn getForm>
		
	</cffunction >
	
	<cffunction name="EmployeeDetails" access="public" returntype="query">
		<cfargument name="pGUID" type="string" required="yes">
		<cfargument name="tDSN" type="string" required="yes">
		
		<cfquery name="getEmployee" datasource="#tDSN#">
			SELECT PERSONNELIDNO, LASTNAME, FIRSTNAME
			FROM CMFPA
			WHERE	(GUID = '#pGUID#')
		</cfquery>
		
		<cfreturn getEmployee>
	</cffunction>
	
	<cffunction name="FieldsFetch" access="public" returntype="query">
		<cfargument name="table_fk" type="string" required="yes">
		<cfargument name="global_dsn" type="string" required="yes">
		<cfquery name="getFields" datasource="#global_dsn#">
			SELECT *
			FROM GRGBOSETABLEFIELDS
			WHERE
			(TABLENAME  = '#table_fk#') AND
			(ISVISIBLEEFORM    = 'Y' OR ISVISIBLEEFORM IS NULL) AND
			(COLUMNNAME <> 'PERSONNELIDNO') AND
			(COLUMNNAME <> 'RECDATECREATED') AND
			(COLUMNNAME <> 'RECCREATEDBY') AND
			(COLUMNNAME <> 'USERID') AND
			(COLUMNNAME <> 'DATELASTUPDATE') AND
			(COLUMNNAME <> 'TIMELASTUPDATE') AND
			(COLUMNNAME <> 'ROUTEID') AND
			(COLUMNNAME <> 'APPROVED') AND
			(#sqlSTRLEN#(COLUMNDESC) > 0) AND
	<!--- Added by soti to hide additional eforms internal fields --->
			(COLUMNNAME <> 'ATTACHMENTCODE')
			ORDER BY FIELDGROUP, COLUMNORDER, COLUMNDESC, COLUMNNAME
		</cfquery>	
	</cffunction>
	
	<cffunction name="FetchEntry" access="public" returntype="query">
		<cfargument name="formQuery" type="query" required="yes">
		<cfargument name="personnel" type="string" required="yes">
		
		SELECT *
			FROM #formQuery.TABLENAME_FK#
			WHERE
				(PERSONNELIDNO = '#personnel#')
				<CFLOOP  INDEX="x" FROM="1" TO="5">
				<cfset m = formQuery["PK_FIELD#x#"]>
				<CFIF m NEQ "" AND IsDefined("url." & #evaluate("formQuery.PK_FIELD" & x)#)>
					<CFSET theVal = evaluate("url." & evaluate("formQuery.PK_FIELD" & x))>
					AND (#ucase(evaluate("formQuery.PK_FIELD" & x))# = '#theVal#')
				</CFIF>
				</CFLOOP>
	</cffunction>
	
</cfcomponent>